package hiho.ku._1032._1;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for (int i = 0; i < n; i++)
			run(in);
	}
	
	private static void run(Scanner in) {
		String s = in.next();
		s = insertSharps(s);
		
		int ans = 0;
		
		int[] f = new int[s.length()];
		f[0] = 1;
		int maxRight = 0;
		int maxRightMid = 0;
		for (int i = 1; i < s.length(); i++) {
			int currentLength = 1;
			if (maxRight >= i)
				currentLength = Math.min(f[maxRightMid * 2 - i], maxRight - i);
			int left = i - currentLength;
			int right = i + currentLength;
			while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
				left--;
				right++;
				currentLength++;
			}
			
			f[i] = currentLength;
			ans = Math.max(ans, currentLength);
			
			if (i + currentLength - 1 > maxRight) {
				maxRight = i + currentLength - 1;
				maxRightMid = i;
			}
		}
		
		System.out.println(ans - 1);
	}
	
	private static String insertSharps(String s) {
		StringBuilder b = new StringBuilder();
		b.append('#');
		for (int i = 0; i < s.length(); i++)
			b.append(s.charAt(i)).append('#');
		return b.toString();
	}

}
